#include "GLSceneProjectionMode.h"

#include "gl.h"

namespace catan
{

/*static*/ void GLSceneProjectionMode::begin(SDLCanvas &sdlCanvas, float xOffset, float yOffset)
{
	GLint oldMatrixMode;
	glGetIntegerv(GL_MATRIX_MODE, &oldMatrixMode);
	    glMatrixMode(GL_PROJECTION);
	    glPushMatrix();
		    glLoadIdentity();
		    glTranslatef(xOffset/sdlCanvas.getWindowUnitWidth(), yOffset/sdlCanvas.getWindowUnitHeight(), 0.0f);  //moves the "image" of the hex map around
		    float halfWidth = sdlCanvas.getWindowUnitWidth()/2;
		    float halfHeight = sdlCanvas.getWindowUnitHeight()/2;
		    glFrustum(-halfWidth, halfWidth, halfHeight, -halfHeight, 1.0f, 65536.0f);
	glMatrixMode(oldMatrixMode);
}

/*static*/ void GLSceneProjectionMode::end()
{
	GLint oldMatrixMode;
	glGetIntegerv(GL_MATRIX_MODE, &oldMatrixMode);
	    glMatrixMode(GL_PROJECTION);
	    glPopMatrix();
	glMatrixMode(oldMatrixMode);
}

/*private*/ GLSceneProjectionMode::GLSceneProjectionMode()
{
}

}